{% extends 'base.html' %}

{% block title %}错题列表{% endblock %}

{% block content %}
<div class="container mt-4">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h1>错题管理</h1>
            <a href="{% url 'core:mistake_create' %}" class="btn btn-primary"><i class="bi bi-plus-circle me-2"></i>添加新错题</a>
        </div>

        <!-- 综合搜索功能 -->
        <form method="get" action="{% url 'core:mistake_list' %}" class="mb-4">
            <div class="row g-3">
                <div class="col-md-3">
                    <div class="input-group">
                        <span class="input-group-text"><i class="bi bi-search"></i></span>
                        <input type="text" name="search" class="form-control" placeholder="搜索标题..." value="{{ request.GET.search|default:'' }}">
                    </div>
                </div>
                <div class="col-md-2">
                    <select name="teacher" class="form-select">
                        <option value="">所有教师</option>
                        {% for teacher in teachers %}
                        <option value="{{ teacher.id }}" {% if request.GET.teacher == teacher.id|stringformat:"i" %}selected{% endif %}>{{ teacher.username }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-2">
                    <select name="subject" class="form-select">
                        <option value="">所有学科</option>
                        {% for subject in subjects %}
                        <option value="{{ subject.id }}" {% if request.GET.subject == subject.id|stringformat:"i" %}selected{% endif %}>{{ subject.name }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-2">
                    <select name="chapter" class="form-select">
                        <option value="">所有章节</option>
                        {% for chapter in chapters %}
                        <option value="{{ chapter.id }}" {% if request.GET.chapter == chapter.id|stringformat:"i" %}selected{% endif %}>{{ chapter.name }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-2">
                    <select name="knowledge_point" class="form-select">
                        <option value="">所有知识点</option>
                        {% for kp in knowledge_points %}
                        <option value="{{ kp.id }}" {% if request.GET.knowledge_point == kp.id|stringformat:"i" %}selected{% endif %}>{{ kp.name }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-1">
                    <select name="star_level" class="form-select">
                        <option value="">所有星级</option>
                        <option value="1" {% if request.GET.star_level == '1' %}selected{% endif %}>1星</option>
                        <option value="2" {% if request.GET.star_level == '2' %}selected{% endif %}>2星</option>
                        <option value="3" {% if request.GET.star_level == '3' %}selected{% endif %}>3星</option>
                        <option value="4" {% if request.GET.star_level == '4' %}selected{% endif %}>4星</option>
                        <option value="5" {% if request.GET.star_level == '5' %}selected{% endif %}>5星</option>
                    </select>
                </div>
            </div>
            <div class="row mt-3">
                <div class="col-md-12 text-center">
                    <button type="submit" class="btn btn-primary me-2"><i class="bi bi-search me-1"></i>搜索</button>
                    <a href="{% url 'core:mistake_list' %}" class="btn btn-outline-secondary"><i class="bi bi-arrow-counterclockwise me-1"></i>重置</a>
                </div>
            </div>
        </form>

        {% if mistakes %}
        <div class="card">
            <div class="card-body">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>学科</th>
                            <th>标题</th>
                            <th>知识点</th>
                            <th>添加教师</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for mistake in mistakes %}
                        <tr>
                            <td>{{ mistake.subject.name }}</td>
                            <td>{{ mistake.title }}</td>
                            <td>{{ mistake.knowledge_point.name }}</td>
                            <td>{{ mistake.create_by }}</td>
                            <td>{{ mistake.created_at|date:"Y-m-d H:i" }}</td>
                            <td>
                                <a href="{% url 'core:mistake_update' mistake.id %}" class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil me-1"></i>编辑</a>
                                <a href="{% url 'core:mistake_delete' mistake.id %}" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash me-1"></i>删除</a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        {% else %}
        <div class="alert alert-info">暂无错题记录，请添加新错题。</div>
        {% endif %}
    </div>
{% endblock %}